package com.java.controller;

import com.java.dao.CustomerDao;
import com.java.entity.Customer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 客户表(Customer)表控制层
 *
 * @author 安能
 * @since 2020-07-01 11:27:15
 */
@RestController
@RequestMapping("customer")
public class CustomerController {



    @Resource
    private CustomerDao customerDao;




    @GetMapping("insert")
    public Customer insert(Customer customer) {
        customerDao.insert(customer);
        return customer;
    }

    @GetMapping("update")
    public Customer update(Customer customer) {
        customerDao.updateById(customer);
        return customer;
    }

    @GetMapping("deleteById")
    public Integer deleteById(Integer id) {
        customerDao.deleteById(id);
        return id;
    }

    @GetMapping("selectList")
    public HashMap<String, Object> selectList() {
        /*
        从CustomerDao获取数据，定义格式后返回给前端
         */
        List<Customer> customers = customerDao.selectList(null);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", customers.size());
        map.put("data", customers);
        return map;
    }
}